home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / GBlanker / GSource / GadTools / interface.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  7KB  |  271 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <dos/dostags.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <graphics/rpattr.h>
  13. #include <graphics/text.h>
  14. #include <libraries/gadtools.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17.  
  18. #include <clib/gadtools_protos.h>
  19. #include <pragmas/gadtools_pragmas.h>
  20.  
  21. #include "Garshneblanker.h"
  22.  
  23. #include "includes.h"
  24. #include "libraries.h"
  25. #include "protos/protos.h"
  26.  
  27. struct Library *GadtoolsBase;
  28.  
  29. __saveds __asm LONG RenderHookFunc( register __a0 struct Hook *hook,
  30.     register __a2 struct Node *Node, register __a1 struct LVDrawMsg *Msg )
  31. {
  32.     struct RastPort *Rast = Msg->lvdm_RastPort;
  33.  
  34.     switch( Msg->lvdm_MethodID )
  35.     {
  36.     case LV_DRAW:
  37.     {
  38.         BlankerEntry *Entry = ( BlankerEntry * )Node;
  39.  
  40.         if( Msg->lvdm_State == LVR_SELECTED )
  41.         {
  42.             LONG OldPen = GetAPen( Rast );
  43.             SetAPen( Rast, ( 1L << Rast->BitMap->Depth ) - 1 );
  44.             RectFill( Rast, Msg->lvdm_Bounds.MinX,
  45.                 Msg->lvdm_Bounds.MinY, Msg->lvdm_Bounds.MaxX,
  46.                 Msg->lvdm_Bounds.MaxY );
  47.             SetAPen( Rast, OldPen );
  48.         }
  49.         else
  50.             EraseRect( Rast, Msg->lvdm_Bounds.MinX,
  51.                 Msg->lvdm_Bounds.MinY, Msg->lvdm_Bounds.MaxX,
  52.                 Msg->lvdm_Bounds.MaxY );
  53.         Move( Rast, Msg->lvdm_Bounds.MinX + 2,
  54.             Msg->lvdm_Bounds.MinY + Rast->TxBaseline );
  55.         if( Entry->be_Disabled )
  56.             SetSoftStyle( Rast, FS_NORMAL, AskSoftStyle( Rast ));
  57.         else
  58.             SetSoftStyle( Rast, FSF_BOLD, AskSoftStyle( Rast ));
  59.         Text( Rast, Entry->be_Name, strlen( Entry->be_Name ));
  60.         SetSoftStyle( Rast, FS_NORMAL, AskSoftStyle( Rast ));
  61.         return LVCB_OK;
  62.     }
  63.     default:
  64.         return LVCB_UNKNOWN;
  65.     }
  66. }
  67. struct Hook RenderHook = {{ 0L, 0L }, ( APTR )RenderHookFunc, 0L, 0L };
  68.  
  69. STRPTR NameSansParens( STRPTR Name )
  70. {
  71.     BYTE Buf[64];
  72.  
  73.     if( Name[0] == '{' )
  74.     {
  75.         strcpy( Buf, Name + 1 );
  76.         Buf[strlen( Buf ) - 1] = '\0';
  77.     }
  78.     else
  79.         return Name;
  80.  
  81.     return Buf;
  82. }
  83.  
  84. STRPTR NameForEntry( struct List *Entries, LONG Entry )
  85. {
  86.     struct Node *Tmp;
  87.  
  88.     for( Tmp = Entries->lh_Head; Entry && Tmp; Tmp = Tmp->ln_Succ, --Entry );
  89.  
  90.     return Tmp ? Tmp->ln_Name : 0L;
  91. }
  92.  
  93. int BT_PREFSClicked( VOID )
  94. {
  95.     if( Stricmp( Prefs->bp_Blanker, "Random" ))
  96.         ExecSubProc( "PrefInterp", "" );
  97.  
  98.     return OK;
  99. }
  100.  
  101. int BT_INFOClicked( VOID )
  102. {
  103.     ExecSubProc( "ShowInfo", ".txt" );
  104.  
  105.     return OK;
  106. }
  107.  
  108. int BT_HIDEClicked( VOID )
  109. {
  110.     return CLOSEWIN;
  111. }
  112.  
  113. int BT_QUITClicked( VOID )
  114. {
  115.     return QUIT;
  116. }
  117.  
  118. int LV_BLANKERSClicked( VOID )
  119. {
  120.     LONG Rand;
  121.     
  122.     MessageModule( "GarshneClient", BM_DOQUIT );
  123.     MessageModule( "GarshnePrefs", BM_DOQUIT );
  124.     strcpy( Prefs->bp_Blanker,
  125.            NameForEntry( BlankerEntries, BlankerMsg.Code ));
  126.     Rand = !Stricmp( Prefs->bp_Blanker, "Random" );
  127.     GT_SetGadgetAttrs( BlankerGadgets[GD_BT_PREFS], BlankerWnd, 0L,
  128.                       GA_Disabled, Rand, TAG_DONE );
  129.     GT_SetGadgetAttrs( BlankerGadgets[GD_BT_TOGGLE], BlankerWnd, 0L,
  130.                       GA_Disabled, Rand, TAG_DONE );
  131.     if( !Rand )
  132.         LoadModule( Prefs->bp_Dir, Prefs->bp_Blanker );
  133.     
  134.     BlankerToEnv( Prefs );
  135.  
  136.     return OK;
  137. }
  138.  
  139. int BT_TOGGLEClicked( VOID )
  140. {
  141.     BlankerEntry *Entry;
  142.     BYTE Path[108];
  143.  
  144.     Entry = ( BlankerEntry * )FindName( BlankerEntries, Prefs->bp_Blanker );
  145.     strcpy( Path, Prefs->bp_Dir );
  146.     AddPart( Path, Prefs->bp_Blanker, 108 );
  147.     strcat( Path, ".disabled" );
  148.     ToggleModuleDisabled( Prefs );
  149.     Entry->be_Disabled = !Entry->be_Disabled;
  150.  
  151.     GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
  152.         GTLV_Labels, ~0, TAG_DONE );
  153.     GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
  154.         GTLV_Labels, BlankerEntries, TAG_DONE );
  155.  
  156.     return OK;
  157. }
  158.  
  159. int BlankerCloseWindow( VOID )
  160. {
  161.     return CLOSEWIN;
  162. }
  163.  
  164. int BlankerVanillaKey( VOID )
  165. {
  166.     switch( BlankerMsg.Code )
  167.     {
  168.     case 'p':
  169.         return BT_PREFSClicked();
  170.     case 'i':
  171.         return BT_INFOClicked();
  172.     case 'h':
  173.         return CLOSEWIN;
  174.     case 't':
  175.         return BT_TOGGLEClicked();
  176.     case 'q':
  177.         return QUIT;
  178.     default:
  179.         return OK;
  180.     }
  181. }
  182.  
  183. VOID CloseInterface( VOID )
  184. {
  185.     if( BlankerWnd )
  186.     {
  187.         WinBox.Left = BlankerWnd->LeftEdge;
  188.         WinBox.Top = BlankerWnd->TopEdge;
  189.         CloseBlankerWindow();
  190.         CloseDownScreen();
  191.     }
  192.  
  193.     if( GadtoolsBase )
  194.     {
  195.         CloseLibrary( GadtoolsBase );
  196.         GadtoolsBase = 0L;
  197.     }
  198. }
  199.  
  200. LONG OpenInterface( VOID )
  201. {
  202.     static BYTE Title[80];
  203.     struct Node *TmpNode;
  204.     LONG i;
  205.  
  206.     if( GadtoolsBase )
  207.         return OK;
  208.  
  209.     if(!( GadtoolsBase = OpenLibrary( "gadtools.library", 37 )))
  210.         return QUIT;
  211.  
  212.     if( !BlankerWnd )
  213.     {
  214.         if( SetupScreen())
  215.             return 1L;
  216.         strcpy( Title, "Garshneblanker ( PopKey=" );
  217.         strcat( Title, Prefs->bp_PopKey );
  218.         strcat( Title, ", BlankKey=" );
  219.         strcat( Title, Prefs->bp_BlankKey );
  220.         strcat( Title, " )" );
  221.         BlankerLeft = WinBox.Left;
  222.         BlankerTop = WinBox.Top;
  223.         OpenBlankerWindow();
  224.         SetWindowTitles( BlankerWnd, FilePart( ProgName ), Title );
  225.     }
  226.     else
  227.     {
  228.         ActivateWindow( BlankerWnd );
  229.         WindowToFront( BlankerWnd );
  230.     }
  231.     
  232.     if( BlankerWnd )
  233.         ScreenToFront( BlankerWnd->WScreen );
  234.     else
  235.         return QUIT;
  236.     
  237.     GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
  238.                       GTLV_Labels, BlankerEntries, TAG_DONE );
  239.  
  240.     for( i = 0, TmpNode = BlankerEntries->lh_Head;
  241.         TmpNode && Stricmp( TmpNode->ln_Name, Prefs->bp_Blanker );
  242.         TmpNode = TmpNode->ln_Succ, i++ );
  243.     if( !TmpNode )
  244.         i = 0;
  245.     GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
  246.                       GTLV_Selected, i, GTLV_MakeVisible, i, GTLV_Top, i,
  247.                       TAG_DONE );
  248.     
  249.     i = !Stricmp( Prefs->bp_Blanker, "Random" );
  250.     GT_SetGadgetAttrs( BlankerGadgets[GD_BT_PREFS], BlankerWnd, 0L,
  251.                       GA_Disabled, i, TAG_DONE );
  252.     GT_SetGadgetAttrs( BlankerGadgets[GD_BT_TOGGLE], BlankerWnd, 0L,
  253.                       GA_Disabled, i, TAG_DONE );
  254.  
  255.     return OK;
  256. }
  257.  
  258. LONG HandleInterface( VOID )
  259. {
  260.     if( !GadtoolsBase )
  261.         return OK;
  262.     
  263.     return HandleBlankerIDCMP();
  264. }
  265.  
  266. ULONG ISigs( VOID )
  267. {
  268.     return BlankerWnd ?( ULONG )( 1L << BlankerWnd->UserPort->mp_SigBit ):
  269.         ( ULONG )0L;
  270. }
  271.